<?php
/**
 * Created by PhpStorm.
 * User: 静静
 * Date: 2019/1/9
 * Time: 9:23
 */

namespace App\CustomTrait;

trait StatusReturnTrait
{
  /**
   * 成功数据返回
   * @param $rel
   * @param string $msg
   * @return \Illuminate\Http\JsonResponse
   */
  public function success($rel = null, $msg = '获取成功', $code = 200)
  {
    $data = [
        'status' => $code,
        'msg' => $msg,
        'data' => $rel
    ];
    return response()->json($data);
  }

  /**
   * 失败数据返回
   * @param null $rel
   * @param string $msg
   * @return array|\Illuminate\Http\JsonResponse
   */
  public function error($rel = null, $msg = '获取失败', $code = 500)
  {
    $data = [
        'status' => $code,
        'msg' => $msg,
        'data' => $rel
    ];
    return response()->json($data);
  }
}